import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type SupplierItemType } from "./supplier";

const SUPPLIER_WITHDRAWN_BASE_URL = "/api";

export const SupplierWithdrawnApi = {
  getSupplierWithdrawnList: (params: ListQuery) => {
    return request.get<any, ListResponse<SupplierWithdrawnItemType>>(
      `${SUPPLIER_WITHDRAWN_BASE_URL}/internal/SupplierWithdrawn/`,
      { params }
    );
  },
  getSupplierWithdrawnDetail: (id: number) => {
    return request.get<any, SupplierWithdrawnItemType>(
      `${SUPPLIER_WITHDRAWN_BASE_URL}/internal/SupplierWithdrawn/${id}/`
    );
  },
  addSupplierWithdrawn: (data: Partial<SupplierWithdrawnForm>) => {
    return request.post(`${SUPPLIER_WITHDRAWN_BASE_URL}/internal/SupplierWithdrawn/`, data, {
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
  updateSupplierWithdrawn: (data: Partial<SupplierWithdrawnForm>) => {
    return request.put(
      `${SUPPLIER_WITHDRAWN_BASE_URL}/internal/SupplierWithdrawn/${data.id}/`,
      data,
      {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      }
    );
  },
  deleteSupplierWithdrawn: (id: number | string) => {
    return request.delete(`${SUPPLIER_WITHDRAWN_BASE_URL}/internal/SupplierWithdrawn/${id}/`);
  },
};

export type SupplierWithdrawnListQuery = {} & ListQuery;

export type SupplierWithdrawnStatus = "approve" | "normal" | "completed";

export type SupplierWithdrawnItemType = {
  id: number | string;
  supplier: SupplierItemType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  amount: string;
  service_cost: string;
  status: SupplierWithdrawnStatus;
  remark: string;
  bank_name: string;
  bank_code: string;
};

export type SupplierWithdrawnForm = {
  id?: number | string;
  real_amount: string;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  amount: string;
  service_cost: string;
  status: string;
  remark: string;
  bank_name: string;
  bank_code: string;
  supplier: number | string;
};

export default SupplierWithdrawnApi;
